<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>原生 JSONP 请求</title>
    <style>
        #result{
            width: 200px;
            height: 200px;
            border:solid 1px #222;
        }
    </style>
</head>
<body>
    <button>点击发送跨域请求</button>
    <div id="result">

    </div>
    <script>
        //获取按钮
        let btn = document.querySelector('button');
        let result = document.querySelector("#result");

        //4. 声明一个回调函数
        function abcxyz(data){
            result.innerHTML = data;
        }
        //绑定单击事件
        btn.onclick = function(){
            //1. 创建一个 script 标签
            let script = document.createElement('script');
            //2. 设置 src 属性
            script.src = 'http://127.0.0.1/jsonp-server?callback=abcxyz';
            //3. 将标签插入到文档中 body 的最后
            document.body.appendChild(script);
        }
    </script>
</body>
</html>